home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGNG_C
/
DBTOOLC.LZH
/
SOURCE.ARC
/
DCT1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1987-09-17
|
32KB
|
1,375 lines
#include <stdio.h>
#include <ctype.h>
#include "dctmain.h"
/*
* NAME:
* DCT1.C - dBASE C Tool (Version 1.4) - Main Module
*
* SYNOPSIS:
*
* DESCRIPTION:
* Contains function table and other globabl initialization,
* and jacketed routines that are called by dBASE.
*
* RETURNS:
* Most functions don't have a C return value; instead, they
* poke a value into a dBASE memory variable
*
* NOTES:
* Ver 1.1 must use the LARGE model, and must be linked with
* c_catch.obj and dctmain.obj
*
* AUTHOR: J. T. Cooper
*
*/
/*
* INSERT YOUR #include STATEMENTS HERE
*/
#ifdef LATTICE
int _stack = 8192;
#endif
/* For Aztec users, the following values replace those in the STKSIZ.O
* module in Aztec's C.LIB library (see Aztec docs)
*/
#ifdef AZTEC
int _STKSIZ = 4096/16; /* (in paragraphs) */
int _HEAPSIZ = (4096+1024)/16; /* (in paragraphs) */
int _STKLOW = 1; /* change to heap above stack */
#endif
/* globals used by many functions */
char dt_token[128]; /* storage for parsing tokens */
char dt_fname[36]; /* retains name function is called by */
char *BigBuf1, *BigBuf2;
/*
* DECLARE YOUR FUNCTIONS
*
* C needs to know the names before getting to the structure assignment.
* We have adopted a convention of dt_... for dispatched functions. Any
* functions you add must be referenced here.
*/
#ifdef MS
int
#else
void
#endif
dt_acos(),
dt_amort(),
dt_arand(),
dt_arestore(),
dt_asave(),
dt_asin(),
dt_atan(),
dt_chi(),
dt_clrwindow(),
dt_corr(),
dt_cos(),
dt_count(),
dt_covar(),
dt_crarray(),
dt_cv(),
dt_dist(),
dt_dumparray(),
dt_eqn(),
dt_fdump(),
dt_frarray(),
dt_fv(),
dt_gen(),
dt_getarray(),
dt_getpass(),
dt_getsize(),
dt_gtn(),
dt_help(),
dt_irr(),
dt_kurt(),
dt_len(),
dt_ltn(),
dt_max(),
dt_median(),
dt_mean(),
#ifdef LATTICE
dt_memstat(),
#endif
dt_min(),
dt_mirr(),
dt_npv(),
dt_nsk(),
dt_peek(),
dt_poke(),
dt_pmt(),
dt_putarray(),
dt_putwindow(),
dt_pv(),
dt_rand(),
dt_range(),
dt_rnarray(),
dt_ros(),
dt_setbell(),
dt_setdvar(),
dt_seterr(),
dt_sf(),
dt_sin(),
dt_skew(),
dt_sound(),
dt_starray(),
dt_stdev(),
dt_tan(),
dt_var();
char *fc_array(); /* returns pointer to an array of a given name */
/*
* The Lattice extern variable _tsize is the current size of the program,
* in paragraphs; this is exactly what db_c_catch() wants, so let's use
* that.
*/
/*
* DO THE STRUCTURE ASSIGN
*
* See DCTMAIN.H for description of elements. This is the table referred to
* in the docs as the 'dispatch' table.
*/
struct ci_DT ci_DispTable[] =
{
"ACOS", dt_acos,
"<x> - Compute arccosine of <x>",
"AMORT", dt_amort,
"<prin>, <rate>, <periods>, <pmts> - Amortization function",
"ARAND",dt_arand,
"<array>[,<factor>, <start>, <end>]",
"ARESTORE", dt_arestore,
"<array>,<filename>[,<start>,<end>] - Restore array from disk",
"ASAVE", dt_asave,
"<array>,<filename>[,<start>,<end>] - Save an array to disk",
"ASIN", dt_asin,
"<x> - Compute arcsine of <x>",
"ATAN", dt_atan,
"<x> - Compute arctangent of <x>",
"CHI", dt_chi,
"<expected>,<observed>[,<size>] - Chi-Squared Statistic",
"CLRWINDOW", dt_clrwindow,
"<y1>,<x1>,<y2>,<x2>,<flag> - Clear a window to spaces",
"CORR", dt_corr,
"<xarray>, <yarray>[,<size>] - Correlation of two arrays",
"COS", dt_cos,
"<r> - Compute cosine of <r> radians",
"COUNT", dt_count,
"<array> - Count the number of items in <array>",
"COVAR", dt_covar,
"<xarray>, <yarray>[,<size>] - Covariance of two arrays",
"CRARRAY", dt_crarray,
"<id>, <n>, <type> - Create an array",
"CV", dt_cv,
"<array>[,<size>] - Calc. coefficient of variance",
"DIST", dt_dist,
"<array>, <d>, <f>[,<size>] - Dist. Frequency",
"DUMPARRAY", dt_dumparray,
"<array>, <first>, <last> - Display contents of an array",
"EQN", dt_eqn,
"<value>, <array>[,<size>] - Number = <value>",
"FDUMPARRAY", dt_fdump,
"<array>, <file>, <first>, <last> - Dump array to file",
"FRARRAY", dt_frarray,
"<id> - Free the array <id>",
"FV", dt_fv,
"<pmt>, <rate>, <term> - Future Value function",
"GEN", dt_gen,
"<value>, <array>[,<size>] - Number >= <value>",
"GETARRAY", dt_getarray,
"<id>, <index> - Get a value from an array",
"GETPASS", dt_getpass,
"- Get a password from the operator",
"GETSIZE", dt_getsize,
"<array> - Return the size of an array",
"GTN", dt_gtn,
"<value>, <array>[,<size>] - Number > <value>",
"HELP", dt_help,
"[function] - List functions in library (you just called it)",
"IRR", dt_irr,
"<guess>, <flows>, <n> - Internal Rate of Return",
"KURT", dt_kurt,
"<zarray>[,<size>] - Sample Kurtosis",
"LTN", dt_ltn,
"<value>, <array>[,<size>] - Number < <value>",
"LEN", dt_len,
"<value>, <array>[,<size>] - Number <= <value>",
"MAX", dt_max,
"<array>[,<size>] - Find largest value in <array>",
"MEAN", dt_mean,
"<array>[,<size>] - Calc. mean average",
"MEDIAN", dt_median,
"<array>[,<size>] - Calc. median average",
#ifdef LATTICE
"MEMSTAT", dt_memstat,
" - Memory status",
#endif
"MIN", dt_min,
"<array>[,<size>] - Find smallest value in <array>",
"MIRR", dt_mirr,
"<risky>, <safe>, <flows>, <n> - Modified IRR",
"NPV", dt_npv,
"<rate>, <array>, <n> - Net Present Value function",
"NSK", dt_nsk,
"<xarray>, <zarray>[,<size>] - Normal Scores",
"PEEK", dt_peek,
"<offset>, <segment> - Peek at a memory location",
"PMT", dt_pmt,
"<prin>, <rate>, <term> - Calc. payment for a loan",
"POKE", dt_poke,
"<bytecode>, <offset>, <segment> - Write a byte into memory",
"PUTARRAY", dt_putarray,
"<id>, <index>, <value> - Put a <value> in an array",
"PUTWINDOW", dt_putwindow,
"<y1>,<x1>,<y2>,<x2>,<clear>,<type>",
"PV", dt_pv,
"<pmt>, <rate>, <term> - Present Value function",
"RAND", dt_rand,
"<lo>, <hi> - Generate random # >= lo && <= hi",
"RANGE", dt_range,
"<array>[,<size>] - Find range of values in <array>",
"RNARRAY", dt_rnarray,
"<id>, <newid> - Rename an array",
"ROS", dt_ros,
"<old>, <new>[,<size>] - Reverse Order Statistics (Sort)",
"SETBELL", dt_setbell,
"<value> - Set error bell on if nonzero",
"SETDVAR", dt_setdvar,
"<type> - Remember next memvar passed to cfunc",
"SETERR", dt_seterr,
"<value> - Set error reporting on if nonzero",
"SF", dt_sf,
"<amt>, <rate>, <periods> - Sinking Fund",
"SIN", dt_sin,
"<r> - Compute sine of <r> radians",
"SKEW", dt_skew,
"<zarray>[,<size>] - Sample Skewness",
"SOUND", dt_sound,
"<frequency>, <duration> - Generate a sound",
"STARRAY", dt_starray,
"Display the status of all arrays",
"STDEV", dt_stdev,
"<array>[,<size>] - Calculate standard deviation",
"TAN", dt_tan,
"<r> - Compute tangent of <r> radians",
"VAR", dt_var,
"<array>[,<size>] - Calc. variance",
"", 0, ""
};
/*
*
* Finally, call db_c_catch().
*
*/
void main(argc, argv)
int argc;
char *argv[];
{
#ifdef LATTICE
drand48(); /* initialize Lattice's random # generator */
#endif
/* db_c_catch needs to know how many pages of memory to save. Part of that
* memory is the actual program size, which we define here. Note that these
* sizes are approximate, and vary widely with different compilers and memory
* models. Some compilers provide the ability to directly access the program
* size, while others do not. Check your compiler manual, and remember that
* Prog_Size + Res_Mem must equal the total amount of memory, including all
* allocation plus about 4K for internal buffers, that will be used by the
* program.
*/
/* Prog_Size should be set to the size of the executable file plus
* the size of the stack plus at least 16 bytes. We round these
* upward to the nearest 1000 bytes in the following assignments
*/
#ifdef LC2
Prog_Size = 84000L; /* assumes LATTICE large model */
#endif
#ifdef LC3
Prog_Size = 80000L;
#endif
#ifdef MS
Prog_Size = 80000L; /* Microsoft large model */
#endif
#ifdef AZTEC
Prog_Size = 50000L; /* assumes AZTEC small model (C Prime) */
#endif
if (argc > 1)
{
#ifdef LARGE
Res_Mem = min(120,atoi(argv[1]) < 0 ? 16 : atoi(argv[1]));
#else
Res_Mem = min(24,atoi(argv[1]) < 0 ? 10 : atoi(argv[1]));
#endif
}
else
{
#ifdef LARGE
Res_Mem = 16;
#else
Res_Mem = 10;
#endif /* LARGE */
}
printf("Reserving %ld bytes for arrays\n",1024L * Res_Mem);
/* we need some reserve for internal use, so bump it up */
Res_Mem += INT_MEM_RESERVE/1024;
/* A bug in Lattice forces us to make two allocation calls, so we split up
the calls to calloc()
*/
#ifdef LATTICE
BigBuf1 = calloc(Res_Mem,512);
BigBuf2 = calloc(Res_Mem,512);
#else
BigBuf1 = calloc(Res_Mem,1024);
#endif
/* Freeing the memory right away assures that we protect our own internal
* memory pool from dBASE shenanigans, as long as we also tell DOS to keep
* the extra memory resident upon termination...
*/
free(BigBuf1);
#ifdef LATTICE
free(BigBuf2);
#endif
BigBuf1 = calloc(INT_MEM_RESERVE-ALLOC_OVHD, 1);
db_c_catch(INTRPT1,INTRPT2,
(unsigned)((((long)Res_Mem + 2L) * 1024L + Prog_Size)/16L));
}
/*
* PUT YOUR DISPATCHED FUNCTIONS HERE
*/
void dt_acos(s)
char *s;
{
double result;
result = acos(atof(ArgVal[1]));
SetNRet(result);
}
void dt_amort(s) /* amortization setup function */
char *s;
{
double prin; /* principle */
double rate; /* interest */
int term; /* term */
int pmts; /* payments made */
double result, amort();
prin = atof(ArgVal[1]);
rate = atof(ArgVal[2]);
term = atoi(ArgVal[3]);
pmts = atoi(ArgVal[4]);
result = amort(prin, rate, term, pmts); /* do the calculation */
SetNRet(result);
}
/* fill an array with random #'s */
void dt_arand(s)
char *s;
{
double factor;
int start, end, n;
double *dest;
#ifdef AZTEC
double ran();
#endif
if (*ArgVal[2])
factor = atof(ArgVal[2]);
else
factor = 1.0;
start = atoi(ArgVal[3]);
end = atoi(ArgVal[4]);
if (!end || end > arsize(ArgVal[1])-1)
end = arsize(ArgVal[1])-1;
if (dest = (double *)fc_array(ArgVal[1]))
{
for(n = start; n <= end; n++)
#ifdef AZTEC
dest[n] = ran() * factor;
#endif
#ifdef LATTICE
dest[n] = drand48() * factor;
#endif
#ifdef MS
dest[n] = ((double) rand()/32768.0) * factor;
#endif
if (n > arcount(ArgVal[1]))
arsetcnt(ArgVal[1], n);
}
factor = (double) n; /* just so's we return a double */
SetNRet(factor);
}
/* restore an array to disk */
void dt_arestore(s)
char *s;
{
double result;
if (*ArgVal[3])
{
if (!(*ArgVal[4]))
sprintf(ArgVal[4], "%u", arsize(ArgVal[1])-1);
}
else
{
sprintf(ArgVal[3], "0");
sprintf(ArgVal[4], "%u", arsize(ArgVal[1])-1);
}
if ((result = (double)rest_arr(ArgVal[1], ArgVal[2],
ArgVal[3], ArgVal[4])) < 0.0)
dctmsg(MSG_IO_ERROR);
SetNRet(result);
}
/* save an array to disk */
void dt_asave(s)
char *s;
{
double result;
if (*ArgVal[3])
{
if (!(*ArgVal[4]))
sprintf(ArgVal[4], "%u", arcount(ArgVal[1])-1);
}
else
{
sprintf(ArgVal[3], "0");
sprintf(ArgVal[4], "%u", arcount(ArgVal[1])-1);
}
if ((result = (double)save_arr(ArgVal[1], ArgVal[2],
ArgVal[3], ArgVal[4])) < 0.0)
dctmsg(MSG_IO_ERROR);
SetNRet(result);
}
void dt_asin(s)
char *s;
{
double result;
result = asin(atof(ArgVal[1]));
SetNRet(result);
}
void dt_atan(s)
char *s;
{
double result;
result = atan(atof(ArgVal[1]));
SetNRet(result);
}
/* dt_chi - chi-square function setup */
void dt_chi(s)
char *s;
{
int size;
double result, chisq();
size = atoi(ArgVal[3]);
if (!size) size = arsize(ArgVal[1]);
result = chisq((double *)fc_array(ArgVal[1]),
(double *)fc_array(ArgVal[2]), size);
SetNRet(result);
}
/* dt_clrwindow - clear a window to spaces */
void dt_clrwindow(s)
char *s;
{
int x1, x2, y1, y2;
int i, j;
int bord_only; /* if non-zero (TRUE), clear only borders */
y1 = atoi(ArgVal[1]);
x1 = atoi(ArgVal[2]);
y2 = atoi(ArgVal[3]);
x2 = atoi(ArgVal[4]);
bord_only = atoi(ArgVal[5]);
for (i = x1; i <= x2; i++)
for (j = y1; j <= y2; j++)
{
if (!bord_only ||
(j == y1) || j == y2 || i == x1 || i == x2)
{
curlocat(j, i);
putchar((int)' ');
}
}
}
void dt_cos(s)
char *s;
{
double result;
result = cos(atof(ArgVal[1]));
SetNRet(result);
}
/* void dt_count - find the total # items in array */
void dt_count(s)
char *s;
{
double result;
result = (double) arcount(ArgVal[1]);
if (result < 0.0)
dctmsg(MSG_NO_ARRAY);
else
SetNRet(result);
}
void dt_crarray(s) /* setup function for creation of arrays */
char *s;
{
double temp;
temp = (double) cr_array(ArgVal[1], ArgVal[2], *ArgVal[3]);
if (temp < 0.0) SetStatus(temp);
else SetNRet(temp);
}
/* dt_corr - correlation of two arrays */
void dt_corr(s)
char *s;
{
int size; /* size of array */
double result, scorr();
double *arpt1, *arpt2;
size = atoi(ArgVal[3]);
if (!size) size = min(arsize(ArgVal[1]), arsize(ArgVal[2]));
if (!(arpt1 = (double *) fc_array(ArgVal[1])) || !(arpt2 =
(double *) fc_array(ArgVal[2])))
return;
result = scorr(arpt1, arpt2, size);
SetNRet(result);
}
/* dt_covar - covariance of two arrays */
void dt_covar(s)
char *s;
{
int size; /* size of array */
double result, scovar();
double *arpt1, *arpt2;
size = atoi(ArgVal[3]);
if (!size) size = min(arsize(ArgVal[1]), arsize(ArgVal[2]));
if (!(arpt1 = (double *) fc_array(ArgVal[1])) || !(arpt2 =
(double *) fc_array(ArgVal[2])))
return;
result = scovar(arpt1, arpt2, size);
SetNRet(result);
}
/* dt_cv - find the coefficient of variance of values in an array */
void dt_cv(s)
char *s;
{
int size; /* size of array */
double result, scv();
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
result = scv((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}
/* dt_dist - produce distribution frequency */
void dt_dist(s)
char *s;
{
int size; /* size of array */
double result;
double *arpt[4];
int i;
for (i = 0; i < 4; i++)
if ((arpt[i] = (double *)fc_array(ArgVal[i+1])) == (char *) 0)
return;
size = atoi(ArgVal[5]);
if (!size) size = arsize(ArgVal[1]);
result = (double) sdist(arpt[0], arpt[1], arpt[2], arpt[3], size);
arsetcnt(ArgVal[2], size);
arsetcnt(ArgVal[3], size);
arsetcnt(ArgVal[4], size);
SetNRet(result);
}
void dt_dumparray(s) /* setup function for dumping array */
char *s;
{
double temp;
if (*ArgVal[2])
{
if (!(*ArgVal[3]))
sprintf(ArgVal[3], "%u", arcount(ArgVal[1])-1);
}
else
{
sprintf(ArgVal[2], "0");
sprintf(ArgVal[3], "%u", arcount(ArgVal[1])-1);
}
temp = (double) dump_array(ArgVal[1], ArgVal[2], ArgVal[3]);
SetNRet(temp);
}
/* dt_eqn - find a value > than a given number */
void dt_eqn(s)
char *s;
{
double value; /* number to be compared */
int size; /* size of array */
double result;
value = atof(ArgVal[1]);
size = atoi(ArgVal[3]);
if (!size) size = arsize(ArgVal[2]);
result = (double) seqn(value, (double *)fc_array(ArgVal[2]), size);
SetNRet(result);
}
void dt_fdump(s) /* setup function for dumping array to file */
char *s;
{
double temp;
if (*ArgVal[3])
{
if (!(*ArgVal[4]))
sprintf(ArgVal[4], "%u", arcount(ArgVal[1])-1);
}
else
{
sprintf(ArgVal[3], "0");
sprintf(ArgVal[4], "%u", arcount(ArgVal[1])-1);
}
temp = (double) fdump_array(ArgVal[1], ArgVal[2],
ArgVal[3], ArgVal[4]);
SetNRet(temp);
}
void dt_frarray(s) /* setup function for freeing arrays */
char *s;
{
double temp;
temp = (double) fr_array(ArgVal[1]);
if (temp < 0.0)
SetStatus(temp);
}
void dt_fv(s) /* future value setup function */
char *s;
{
double pmt; /* payment per term */
double interest; /* interest per term */
int term; /* term of note */
double result, /* place to hold result */
fv(); /* actual calculation done by this guy */
pmt = atof(ArgVal[1]);
interest = atof(ArgVal[2]);
term = atoi(ArgVal[3]);
result = fv(pmt, interest, term);
SetNRet(result);
}
/* dt_gen - find a value >= than a given number */
void dt_gen(s)
char *s;
{
double value; /* number to be compared */
int size; /* size of array */
double result;
value = atof(ArgVal[1]);
size = atoi(ArgVal[3]);
if (!size) size = arsize(ArgVal[2]);
result = (double) sgen(value, (double *)fc_array(ArgVal[2]), size);
SetNRet(result);
}
void dt_getarray(s) /* setup function for getting values from arrays */
char *s;
{
double temp;
temp = (double) get_arv(ArgVal[1], ArgVal[2]);
if (temp < 0.0)
SetStatus(temp);
}
/* dt_gtn - find a value > than a given number */
void dt_gtn(s)
char *s;
{
double value; /* number to be compared */
int size; /* size of array */
double result;
value = atof(ArgVal[1]);
size = atoi(ArgVal[3]);
if (!size) size = arsize(ArgVal[2]);
result = (double) sgtn(value, (double *)fc_array(ArgVal[2]), size);
SetNRet(result);
}
/* setup function for password */
void dt_getpass(s)
char *s;
{
char passbuf[10];
/*
DB_ERRFLG = atoi(dt_token);
*/
/* Get a 1 to 8 character password. Only the enter key terminates the input.
* Ring the bell on an invalid response. Backspace key will delete
* characters. No automatic return
*/
getpass(8, 1, 1, 0, passbuf, 1, '#');
SetCRet(passbuf);
}
/* dt_getsize - return the size of an array */
void dt_getsize(s)
char *s;
{
double result;
result = (double) arsize(ArgVal[1]);
SetNRet(result);
}
/* dt_help simply lists all the functions available to the user */
void dt_help(s)
char *s;
{
int i;
putwindow(1,0,(*ArgVal[1] ? 3 : 11),79, BigBuf1, 1, 1);
for (i = 0; ci_DispTable[i].F_Ptr; i++)
{
if (*ArgVal[1] == '\0')
{
curlocat(2+(i/7),1+((i % 7)*10));
printf("%s", ci_DispTable[i].F_Name);
}
else if (strccmp(ci_DispTable[i].F_Name, ArgVal[1]) == 0)
{
curlocat(2,1);
printf("%s %s", ci_DispTable[i].F_Name,
ci_DispTable[i].F_Descr);
break;
}
}
if (*ArgVal[1] && !ci_DispTable[i].F_Ptr)
{
curlocat(2,1);
printf(" No such function.");
}
getkeycl(&i);
if (i != 0x1b)
rstwindo(1,0,(*ArgVal[1] ? 3 : 11),79, BigBuf1);
}
void dt_irr(s) /* internal rate of return setup function */
char *s;
{
double guess; /* initial guess */
int term; /* term */
double result, irr();
guess = atof(ArgVal[1]);
term = atoi(ArgVal[3]);
if (!term) term = arsize(ArgVal[2]);
result = irr(guess, (double *)fc_array(ArgVal[2]), term);
SetNRet(result); /* put result in memvar */
}
/* dt_kurt - calculate kurtosis of normal scores */
void dt_kurt(s)
char *s;
{
int size; /* size of array */
double result, skurt();
double *arpt1;
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
if (!(arpt1 = (double *) fc_array(ArgVal[1])))
return;
result = skurt((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}
/* dt_len - find a value <= than a given number */
void dt_len(s)
char *s;
{
double value; /* number to be compared */
int size; /* size of array */
double result;
value = atof(ArgVal[1]);
size = atoi(ArgVal[3]);
if (!size) size = arsize(ArgVal[2]);
result = (double) slen(value, (double *)fc_array(ArgVal[2]), size);
SetNRet(result);
}
/* dt_ltn - find a value < than a given number */
void dt_ltn(s)
char *s;
{
double value; /* number to be compared */
int size; /* size of array */
double result;
value = atof(ArgVal[1]);
size = atoi(ArgVal[3]);
if (!size) size = arsize(ArgVal[2]);
result = (double) sltn(value, (double *)fc_array(ArgVal[2]), size);
SetNRet(result);
}
/* dt_max - find the maximum value in an array */
void dt_max(s)
char *s;
{
int size; /* size of array */
double result, smax();
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
result = smax((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}
/* dt_mean - find the mean average of values in an array */
void dt_mean(s)
char *s;
{
int size; /* size of array */
double result, smean();
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
result = smean((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}
#ifdef LATTICE
/* dt_memstat - report memory status */
void dt_memstat(s)
char *s;
{
double memavail;
memavail = (double) (sizmem() - INT_MEM_RESERVE < 0L ? 0L :
sizmem()-INT_MEM_RESERVE);
SetNRet(memavail);
}
#endif
/* dt_median - find the median average of values in an array */
void dt_median(s)
char *s;
{
int size; /* size of array */
double result, smedian();
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
result = smedian((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}
void dt_min(s)
char *s;
{
int size; /* size of array */
double result, smin();
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
result = smin((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}
void dt_mirr(s) /* modified internal rate of return setup function */
char *s;
{
double risky, safe; /* risky & safe interest rates */
int term; /* term */
double result, mirr();
risky = atof(ArgVal[1]);
safe = atof(ArgVal[2]);
term = atoi(ArgVal[4]);
if (!term) term = arsize(ArgVal[3]);
result = mirr(risky, safe, (double *)fc_array(ArgVal[3]), term);
SetNRet(result); /* put result in memvar */
}
/* dt_nsk - produce normal scores from array */
void dt_nsk(s)
char *s;
{
int size; /* size of array */
double result;
double *arpt1, *arpt2;
size = atoi(ArgVal[3]);
if (!size) size = arsize(ArgVal[2]);
if (!(arpt1 = (double *) fc_array(ArgVal[1])) || !(arpt2 =
(double *) fc_array(ArgVal[2])))
return;
snsk(arpt1, arpt2, size);
arsetcnt(ArgVal[2], size); /* reset count of array2 */
result = (double) size;
SetNRet(result);
}
void dt_npv(s) /* net present value setup function */
char *s;
{
double interest; /* interest */
int term; /* term */
double result, npv();
interest = atof(ArgVal[1]);
term = atoi(ArgVal[3]);
result = npv(interest, (double *)fc_array(ArgVal[2]), term);
SetNRet(result);
}
/* setup for memory peek function */
void dt_peek(s)
char *s;
{
unsigned offset, segment;
char bytecode;
double result;
offset = atoi(ArgVal[1]);
segment = atoi(ArgVal[2]);
bytecode = peekbyte(offset, segment);
result = (double) bytecode;
SetNRet(result);
}
void dt_pmt(s) /* pmt setup function */
char *s;
{
double prin; /* principle */
double rate; /* interest */
int term; /* term */
double result, pmt();
prin = atof(ArgVal[1]);
rate = atof(ArgVal[2]);
term = atoi(ArgVal[3]);
result = pmt(prin, rate, term); /* do the calculation */
SetNRet(result);
}
/* setup for memory poke function */
void dt_poke(s)
char *s;
{
unsigned offset, segment;
char bytecode;
bytecode = (char)atoi(ArgVal[1]);
offset = atoi(ArgVal[2]);
segment = atoi(ArgVal[3]);
pokebyte(bytecode, offset, segment);
}
void dt_putarray(s) /* setup function for putting values into arrays */
char *s;
{
char id[13];
char index[20];
char value[255];
double temp;
s = GetFunc(dt_token, s);
s = GetNext(id, s);
s = GetNext(index, s);
s = GetString(value, s);
temp = (double) put_arv(id, index, value);
if (temp < 0.0) SetStatus(temp);
else SetNRet(temp);
}
/* setup for putwindow function */
void dt_putwindow(s)
char *s;
{
int x1,y1,x2,y2;
int type; /* 0 =single line, non-zero =double line */
int clear; /* non-zero will clear contents of window */
y1 = atoi(ArgVal[1]);
x1 = atoi(ArgVal[2]);
y2 = atoi(ArgVal[3]);
x2 = atoi(ArgVal[4]);
clear = atoi(ArgVal[5]);
type = atoi(ArgVal[6]);
putwindow(y1,x1,y2,x2,(int *)0,clear,type);
}
void dt_pv(s) /* present value setup function */
char *s;
{
double pmt; /* payment */
double interest; /* interest */
int term; /* term */
double result, pv();
pmt = atof(ArgVal[1]);
interest = atof(ArgVal[2]);
term = atoi(ArgVal[3]);
result = pv(pmt, interest, term); /* do the calculation */
SetNRet(result);
}
void dt_rand(s) /* Setup function for random number generation */
char *s;
{
int low, high, w, temp;
#ifdef LC2
long newseed;
#endif
#ifdef LC3
unsigned newseed;
#endif
#ifdef MS
unsigned newseed;
#endif
double result;
#ifdef AZTEC
double dtemp, ran();
#endif
if (*ArgVal[2])
{
low = atoi(ArgVal[1]);
high = atoi(ArgVal[2]);
w = high - low + 1; /* width of range */
#ifdef AZTEC
temp = (int)(ran() * w);
#else
temp = rand();
temp /= (32767/w); /* make sure it's in range */
#endif
result = (double) ( temp+low >= high ? high : temp + low);
}
else
{
#ifndef AZTEC
if (*ArgVal[1])
#endif
#ifdef AZTEC
result = ran();
#endif
#ifdef LC2
{
newseed = atol(ArgVal[1]);
srand48(newseed);
}
result = drand48();
#endif
#ifdef LC3
{
newseed = (unsigned int)atoi(ArgVal[1]);
srand48((long)newseed);
}
result = drand48();
#endif
#ifdef MS
{
newseed = (unsigned int)atoi(ArgVal[1]);
srand(newseed);
}
result = (double) rand();
#endif
}
SetNRet(result);
}
/* dt_range - find the range of values in an array */
void dt_range(s)
char *s;
{
int size; /* size of array */
double result, srange();
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
result = srange((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}
/* setup function for renaming arrays */
void dt_rnarray(s)
char *s;
{
double temp;
temp = (double) rn_array(ArgVal[1], ArgVal[2]);
SetStatus(temp);
}
/* dt_ros - produce reverse order statistics (sorted array) */
void dt_ros(s)
char *s;
{
int size; /* size of array */
double result;
double *arpt1, *arpt2;
size = atoi(ArgVal[3]);
/* only sort as many as destination array will hold */
if (!size) size = arsize(ArgVal[2]);
if (!(arpt1 = (double *) fc_array(ArgVal[1])) || !(arpt2 =
(double *) fc_array(ArgVal[2])))
return;
result = (double) sros(arpt1, arpt2, size);
arsetcnt(ArgVal[2], size); /* reset count of array2 */
SetNRet(result);
}
/* dt_setdvar informs the package that the next thing passed from
* dbase will be the address of the contents of a memory variable.
* In this way, the location of those contents can be remembered, and
* we can communicate with dbase
*/
void dt_setdvar(s)
char *s;
{
DB_VARTYPE = toupper(*ArgVal[1]);
if (DB_VARTYPE != 'C' && DB_VARTYPE != 'D' && DB_VARTYPE != 'L'
&& DB_VARTYPE != 'N' && DB_VARTYPE != 'S'
&& DB_VARTYPE != 'M' && DB_VARTYPE != 'E')
dctmsg(MSG_INV_TYPE);
else
DB_SETFLAG = 1; /* set up to remember dbase variable */
}
/* set error bell flag */
void dt_setbell(s)
char *s;
{
DB_BELLFLG = atoi(ArgVal[1]);
}
void dt_seterr(s) /* set error reporting flag */
char *s;
{
DB_ERRFLG = atoi(ArgVal[1]);
}
void dt_sf(s) /* sinking fund setup function */
char *s;
{
double prin; /* principle */
double rate; /* interest */
int term; /* term */
double result, sf();
prin = atof(ArgVal[1]);
rate = atof(ArgVal[2]);
term = atoi(ArgVal[3]);
result = sf(prin, rate, term); /* do the calculation */
SetNRet(result);
}
void dt_sin(s)
char *s;
{
double result;
result = sin(atof(ArgVal[1]));
SetNRet(result);
}
/* dt_skew - calculate skewness of normal scores */
void dt_skew(s)
char *s;
{
int size; /* size of array */
double result, sskew();
double *arpt1;
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
if (!(arpt1 = (double *) fc_array(ArgVal[1])))
return;
result = sskew(arpt1, size);
SetNRet(result);
}
/* setup for generating sound */
void dt_sound(s)
char *s;
{
int frequency;
unsigned duration;
frequency = atoi(ArgVal[1]);
duration = atoi(ArgVal[2]);
/* frequencies less than 20 cause a divide overflow */
sound(frequency < 20 ? 20 : frequency, duration);
}
void dt_starray(s) /* setup function for getting array status info */
char *s;
{
double temp;
temp = (double) st_arrays();
SetStatus(temp);
}
/* dt_stdev - find the standard deviation of values in an array */
void dt_stdev(s)
char *s;
{
int size; /* size of array */
double result, sstdev();
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
result = sstdev((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}
void dt_tan(s)
char *s;
{
double result;
result = tan(atof(ArgVal[1]));
SetNRet(result);
}
/* dt_var - find the variance of values in an array */
void dt_var(s)
char *s;
{
int size; /* size of array */
double result, svar();
size = atoi(ArgVal[2]);
if (!size) size = arsize(ArgVal[1]);
result = svar((double *)fc_array(ArgVal[1]), size);
SetNRet(result);
}